# -*- coding: utf-8 -*-

#控制台版本，对GUI程序函数的要求进行了一些改造，改造由张红于2010-03-15日完成


import glob, shutil
import os, sys
import time, math

filelist = [0]
str1 = ""
str2 = ""
def listvideo():                #将可以播放的flv/f4v/mp3格式文件列出
    i = 1
    global filelist
    cachepath = os.environ.get('userprofile') + '\Local Settings\Temporary Internet Files\Content.IE5'
    dirlist = glob.glob(cachepath + '\\*')
    for item in dirlist:
        if os.path.isdir(item):
            onefilelist = glob.glob(item + '\*.flv') + glob.glob(item + '\*.mp3') + glob.glob(item + '\*.f4v')
            for flv in onefilelist:
                filelist.append(flv)
                i = i + 1

def savevideo(n, path):                #将文件复制到用户指定的目录中
    global filelist
    shutil.copy(filelist[n], path)
#    os.rename(filelist[n], os.path.join(path, name))
   

def viewvideo(n):                #播放用户指定的文件
    global filelist
    os.popen('start ' + '\"\" ' + '\"' + filelist[n + 1] + '\"')
    
def detail_of_file(n):           #显示文件的详细信息
    global filelist
    global str1, str2
    str1 = "Time of creation:\nTime of last modification:\n" \
           + "Time of last access:\nSize:"
    str2 = time.ctime(os.path.getctime(filelist[n]))+ '\n'\
           + time.ctime(os.path.getmtime(filelist[n])) + '\n'\
           + time.ctime(os.path.getatime(filelist[n])) + '\n'\
           + str(os.path.getsize(filelist[n])/1024) + 'KB'
    
def menu():
    print "********************************"
    print "* 1.Preview the file.          *"                    #预览视频文件或音乐
    print "* 2.Show details of the file.  *"                    #显示文件的详细信息
    print "* 3.Store the file.            *"                    #存储视频文件或音乐
    print "* 4.Quit.                      *"
    print "********************************"
    return int(raw_input('Please choose the number:'))

if __name__ == '__main__':
    raw_input('Press Enter to continue...')
    print('\nFiles in IE cache dir that can be play:')          #缓存中可播放的文件列表如下
    listvideo()
    n = 0
    while n != 4:
        if len(filelist) > 1:
            pass
        else:
            print 'No File found,Program will exit!'
            raw_input('Press Enter to Quit...')
            break    
        n = menu()
        if n == 1:
            viewvideo()
        elif n == 2:
            detail_of_file()
        elif n == 3:
            savevideo()
        else:
            print('Goodbye!')
            break
        print '\n'
        print('\nFiles in IE cache dir that can be play:')
        listvideo()








    
